<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link href="/Public/css/bootstrap.min.css" rel="stylesheet">
    <script src="/Public/js/jquery-1.11.1.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="/Public/ueditor/ueditor-index.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="/Public/ueditor/ueditor.all.min.js"> </script>
    <script type="text/javascript" charset="utf-8" src="/Public/ueditor/lang/zh-cn/zh-cn.js"></script>
    <script src="/Public/js/bootstrap.min.js"></script>
    <script src="/Public/js/bootstrap-filestyle.js"></script>
    <script src="/lianxi/app.js"></script>
    <style>
        html,body,ul,ul li{margin: 0;padding: 0;border:0;}
        ul{list-style: none;}
        ul a{display: block;text-decoration: none;}
        ul a:hover{text-decoration: underline;}
    </style>
</head>
<body>
<div style="width: 50%;margin: auto;margin-top: 50px;">
    <div class="panel panel-primary">
        <div class="panel-heading">
            <span class="glyphicon glyphicon-user"></span>
            <span>新闻编辑</span>
        </div>
        <form class="form-horizontal">
            <div class="panel-body" id="panelbody">
                <div class="alert  alert-success" id="success" style="display: none">添加成功！！<button class="close" data-dismiss="alert">&times;</button></div>
                    <div class="form-group">
                        <label class="control-label col-xs-2">标题</label>
                        <div class="col-xs-9">
                            <div class="input-group">
                                    <span class="input-group-addon">
                                        <span class="glyphicon glyphicon-tag"></span>
                                    </span>
                                <input type="text" class="form-control" name="title">
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-xs-2">图片</label>
                        <div class="col-xs-9">
                            <input class="filestyle" type="file" name="file">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-xs-2">内容</label>
                        <div class="col-xs-9">
                            <script id="editor" name="content" type="text/plain" style="height:300PX;"></script>
                        </div>
                    </div>
            </div>
            <div class="panel-footer">
                <button type="button" class="btn btn-primary pull-right" id="add">添加</button>
                <button type="button" class="btn btn-success pull-right" id="change">切换登录</button>
                <button type="button" class="btn btn-warning pull-right" id="returnbutton">返回新闻首页</button>
                <div class="clearfix"></div>
            </div>
        </form>
    </div>
</div>
<script>
    var ue = UE.getEditor('editor');
    var form=$('form');
    var panelbody=$('#panelbody');
    var success = $('#success');
    var add=$('#add');
    var change=$('#change');
    var returnbutton = $('#returnbutton');
    add.click(function(){
        var formData = new FormData(form.get(0));
        $.ajax({
            url:'{:U("Xm/file")}',
            data:formData,
            type:'post',
            dataType:"json",
            processData:false,
            contentType:false,
            success:function(resp){
                if(resp.status==false){
                    panelbody.showAlert(resp.mes);
                }else {
                    success.show();
                    setTimeout(function(){
                        success.hide();
                    },3000)
                }
            }
        });
    });

    change.click(function(){
        $.get('{:U("Xm/change")}',function(){
            location = '{:U("Xm/login")}';
        });
    });

    returnbutton.click(function(){
        location = '{:U("Xm/xinwen")}';
    })
</script>
</body>
</html>